package cn.ml.web1662.entity;


import java.util.Collection;

public class Pagination<E> {

    private int currentPageIndex; // 当前页
    private int totalCount;//总记录数
    private int pageSize;//每页数据量
    private Collection<E> result;//每页上显示数据的集合

    public int getCurrentPageIndex() {
        return currentPageIndex;
    }

    public void setCurrentPageIndex(int currentPageIndex) {
        this.currentPageIndex = currentPageIndex;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Collection<E> getResult() {
        return result;
    }

    public void setResult(Collection<E> result) {
        this.result = result;
    }
    //--------------上面定义的是读写属性------------------------
    //是否首页
    public boolean isFirstPage(){
        return getCurrentPageIndex()==1;
    }
    //是否尾页
    public boolean isLastPage(){
        return getCurrentPageIndex()==getTotalPageCount();
    }
    //计算总页数
    public int getTotalPageCount(){
        return (getTotalCount()+(getPageSize()-1))/getPageSize();
    }
    //当前页的其实记录号
    public int getFirstRecordNo(){
        return (getCurrentPageIndex()-1)*getPageSize()+1;  //getCurrentPageIndex()*getPageSize()-getPageSize()+1;
    }
    //当前页的末尾记录号
    public int getLastRecordNo(){
        if(isLastPage()){
            return getTotalCount();
        }
        return getFirstRecordNo()+getPageSize()-1; //getCurrentPageIndex()*getPageSize();
    }
}
